import Base from '../base.js';
import Login from './login.js';
export default class Register extends Base {
    render() {
        this.$app.html(`
        <div style='width:300px;margin:100px auto'>
            <form class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名：</label>
                    <div class="layui-input-block">
                        <input type="text" id="username" required placeholder="请输入用户名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码：</label>
                <div class="layui-input-block">
                    <input type="password"  id="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-block">
                    <button type='button' id='toLogin' class="layui-btn" lay-submit lay-filter="formDemo">注册</button>
                    <button type="reset"  class="layui-btn layui-btn-primary">重置</button>
                </div>
                </div>
            </form>
       </div>
        `)
    }
    handle() {
        $("#toLogin").click(() => {
            $.ajax({
                type: "post",
                url: "http://127.0.0.1:4000/reg",
                data: {
                    "username": $("#username").val(),
                    "pwd": $("#password").val()
                },
                dataType: "json",
                success: (data) => {
                    //console.log(data)
                    if (data.code == 1) {
                        alert(data.msg);
                        new Login("app");
                    } else {
                        alert(data.msg);
                    }
                }
            })
        })
    }
}
new Register('app')